package com.csq.common.util;

import javax.servlet.http.HttpServletRequest;

import com.csq.common.pojo.ReturnResult;
import com.csq.common.pojo.StatusCode;
import com.csq.manager.pojo.Account;
import com.csq.manager.pojo.Enterprise;

public class LoginUtil {
	/**
	 * 
	 * @param request
	 * @return
	 */
	public static ReturnResult checkAccountLogin(HttpServletRequest request) {
		Account account = (Account) request.getSession()
				.getAttribute("account");
		if (account == null) {
			return ReturnResult.build(StatusCode.NOLOGIN,
					"redirect:http://localhost:8080/sso-web/web/account/login");
		} else {
			ReturnResult returnResult = new ReturnResult();
			returnResult.setMessage("login success");
			returnResult.setObject(account);
			returnResult.setState(StatusCode.SUCCESS);
			return returnResult;
		}
	}

	/**
	 * 
	 * @param request
	 * @return
	 */
	public static ReturnResult checkEnterpriseLogin(HttpServletRequest request) {
		Enterprise enterprise = (Enterprise) request.getSession().getAttribute(
				"enterprise");
		if (enterprise == null) {
			return ReturnResult.build(StatusCode.NOLOGIN,
					"redirect:http://localhost:8080/sso-web/web/company/login");
		} else {
			ReturnResult returnResult = new ReturnResult();
			returnResult.setMessage("login success");
			returnResult.setObject(enterprise);
			returnResult.setState(StatusCode.SUCCESS);
			return returnResult;
		}
	}
}
